package com.freewater.parking.domain.parking;


import com.freewater.parking.domain.common.DomainEvent;
import com.freewater.parking.domain.common.DomainEventListener;

public class AlarmPolicy implements DomainEventListener {

    private final AlarmService alarmService;

    public AlarmPolicy(AlarmService alarmService) {
        this.alarmService = alarmService;
    }


    @Override
    public void onEvent(DomainEvent event) {
        if (event instanceof CheckInFailedEvent checkInFailedEvent) {
            alarmService.alarm(checkInFailedEvent.getPlateNumber(), "车辆入场失败");
        } else if (event instanceof CheckOutFailedEvent checkOutFailedEvent) {
            alarmService.alarm(checkOutFailedEvent.getPlateNumber(), checkOutFailedEvent.getCause());
        }
    }
}
